package cn.edu.sctu.sctu_lysd.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cn.edu.sctu.sctu_lysd.R;
import cn.edu.sctu.sctu_lysd.bean.Area;
import cn.edu.sctu.sctu_lysd.utils.L;

/**
 * Created by wangfuxin on 2017-04-14.
 */

public class AreaListAda extends BaseAdapter {

    private Context mContext;
    private List<Area> data;
    private LayoutInflater inflater;
    private TextView textView;
    private View view;

    public AreaListAda(Context mContext, List<Area> data) {
        this.mContext = mContext;
        this.data = data;

        inflater = LayoutInflater.from(mContext);

    }

    public void dataChange(List<Area> list) {

        this.data = list;
        this.notifyDataSetChanged();

    }

    @Override
    public int getCount() {

        if (data != null) {
            return data.size();
        }

        return 0;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        view = inflater.inflate(R.layout.item_area, null);
        textView = (TextView) view.findViewById(R.id.item_area_txt);
        textView.setText(data.get(position).getName());
        return view;
    }
}
